package sort

//选择排序
func SelectSort(array []int, desc bool) []int {
	length := len(array)
	if length < 2 {
		return array
	}
	for i := 0; i < length; i++ {
		top := i
		for j := i + 1; j < length; j++ {
			if array[top] > array[j] && !desc {
				top = j
			}
			if array[top] < array[j] && desc {
				top = j
			}
		}
		if i != top {
			array[i], array[top] = array[top], array[i]
		}
	}
	return array
}
